<template>

  <el-container class="home_container">
    <!--头部区域-->
    <el-header>
      <div>
        <span>电商后台管理系统</span>
      </div>
      <el-button type="info" @click="logout">退出</el-button>
    </el-header>
    <!--    页面主题体区 -->
    <el-container>
      <!--      侧边栏-->
      <el-aside :width="iscollapse ?'64px' :'200px'">
        <div class="zhediekuang" @click="zhedie">|||</div>
        <!-- 侧边菜单栏区域-->
        <el-menu
           :default-active = "$route.path"
            background-color="#333744"
            text-color="#fff"
            active-text-color="#409BFF"
            unique-opened  :collapse="iscollapse"
            :collapse-transition="false"
            router  >
          <!--  一级菜单 -->
          <el-submenu :index="item.id + ''" v-for="item in menulist" :key="item.id">
            <!--   一级菜单模板区-->
            <template slot="title">
              <!--图标 -->
              <i :class="iconimg[item.id]"></i>
              <!--文本-->
              <span>{{ item.authName}}</span>
            </template>
<!--            二级菜单-->

              <el-menu-item :index="'/' + subItem.path" v-for="subItem in item.children">
                <template slot="title">
                  <!--图标 -->
                  <i class="el-icon-menu"></i>
                  <!--文本-->
                  <span>{{subItem.authName}}</span>
                </template>
              </el-menu-item>

          </el-submenu>

        </el-menu>
      </el-aside>
      <!--      右侧内容主题体-->
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  name: "Home",
  data () {
    return {
      //左侧菜单数据
      menulist:[],
      iconimg:{
        '125':'el-icon-user-solid',
        '103':'el-icon-key',
        '101':'el-icon-shopping-cart-1',
        '102':'el-icon-document-copy',
        '145':'el-icon-coin',
      },
      iscollapse:false
    }
  },
  created() {
    //页面一加载获取所有的左侧菜单
    this.getMenuList()
    },
  methods: {
    logout() {
      window.sessionStorage.removeItem('token');
      // window.sessionStorage.clear();
      this.$router.push('/login');
    },
    //获取所有的菜单
    async getMenuList () {
      const {data:res} = await this.$http.get('menus')  //因为get他的返回值是pormise   所以为了简化pormise操作  要加上await修饰
      if(res.meta.status !== 200) return console.log("获取数据失败")
      this.menulist = res.data
      console.log(res)
    },

    //折叠和展开
    zhedie () {
        this.iscollapse = !this.iscollapse
    }
  }
}
</script>

<style lang="less" scoped>
.home_container {
  height: 100%;

}

.el-header {
  background-color: #373D41;
  display: flex;
  justify-content: space-between; //左右贴边对齐
  align-items: center; //左右边的居中
  color: #fff;
  font-size: 20px;
}

.el-aside {
  background-color: #333744;
  transition: all 0.5s;   //过度动画
.el-menu {
  border-right: none;
}
}

.el-main {
  background-color: #EAEDF1;
}
.zhediekuang {
  background-color: #4A5064;
  font-size: 10px;
  text-align: center;
  color: #fff;
  line-height: 22px;
  letter-spacing: 0.2em;//字体间距
  cursor:pointer;//鼠标放上去变成小手
}
</style>